package com.powervision.thirdlogindemo.utils

import android.content.Context
import android.content.pm.ApplicationInfo
import android.content.pm.PackageManager
import android.text.TextUtils
import android.util.Log
import com.powervision.thirdlogindemo.utils.Constant.Companion.mFaceBookPkgName

/**
 * @auth: njb
 * @date: 2021/10/25 17:31
 * @desc: 检查是否安装某App工具类
 */
object CheckApkExistUtils {
    private const val TAG = "CheckApkExist.class"

    private  fun checkApkExist(context: Context, packageName: String?): Boolean {
        return if (TextUtils.isEmpty(packageName)) false else try {
            val info: ApplicationInfo = context.packageManager
                .getApplicationInfo(packageName.toString(),
                    PackageManager.GET_UNINSTALLED_PACKAGES)
            Log.d(TAG,info.toString())
            true
        } catch (e: PackageManager.NameNotFoundException) {
            Log.d(TAG,e.toString())
            false
        }
    }

    fun checkFacebookExist(context: Context): Boolean {
        return checkApkExist(context, mFaceBookPkgName)
    }
}